<?php
namespace app\index\controller;

use app\common\controller\HomeBase;
use app\common\model\Forumcate as ForumcateModel;
use app\common\model\NavCms as NavModel;
use think\Cache;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Tag extends HomeBase
{
    protected $site_config;

    public function _initialize()
    {
        parent::_initialize();
        if (CBOPEN == 2) {
            $this->redirect(url('bbs/index/index'));
        }

        $this->site_config = Cache::get('site_config');
    }

    public function index()
    {
        // tag标签展示关联文章
        $ks  = input('vname');
        $kss = urldecode(input('vname'));
        if (empty($ks) || $kss == '') {
            return $this->error('亲！你没有输入关键字');
        } else {
            
    //   下面这是加的缓存
       $about_shuju = 'tag_'.$kss;
        if (Cache::has($about_shuju)) {
            $tptc = Cache::get($about_shuju);
        } else {
            $article      = Db::name('article');
            $open['open'] = 1;
            $map['f.title|f.keywords|f.description|f.content'] = ['like', "%{$kss}%"];
            $tptc = $article->alias('f')->join('articlecate c', 'c.id=f.tid')->join('user m', 'm.id=f.uid')->field('f.*,c.id as cid,m.id as userid,m.userhead,m.username,c.name,c.template')->order('f.id desc')->where($open)->where($map)->paginate(12, false, $config = ['query' => array('q' => $ks)]);
            Cache::set($about_shuju, $tptc);
        }

            $this->assign('tptc', $tptc);
        // 如果内容不存在
        if(empty($tptc[0])){
            throw new \think\exception\HttpException(404, '页面不存在~');
        }
        return yasuo_html($this->fetch());

    }

}

}
